package com.fenshi.presenter.imp;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.android.volley.VolleyError;
import com.fenshi.bean.OrderBean;
import com.fenshi.interactor.OrderInteractor;
import com.fenshi.interactor.imp.OrderInteractorImp;
import com.fenshi.manager.R;
import com.fenshi.manager.activity.car.CurrentCarActivity;
import com.fenshi.presenter.listener.RequestListener;
import com.fenshi.until.CookicUntil;
import com.fenshi.until.MethodType;
import com.fenshi.view.OrderDetailView;

/**
 * Created by lilongfei on 15/10/4.
 */
public class OrderPresenterImp implements RequestListener<OrderBean> {

    Context c;
    OrderDetailView view;
    OrderInteractor interactor;
    OrderBean card;

    public OrderPresenterImp(Context c) {
        this(c, (OrderDetailView) c);
    }

    public OrderPresenterImp(Context c, OrderDetailView view) {
        this.c = c;
        this.view = view;
        this.interactor = new OrderInteractorImp(c, this);
    }



    public void getOrder(){
        view.showLoad();
        OrderBean order = (OrderBean) ((Activity) c).getIntent().getExtras().getSerializable(CookicUntil.ORDER);
        String userId = CookicUntil.getUser().getUserId();
        interactor.getOrder(userId,order.getOrderCode());
    }

    public void CurrentCar(){
       String cardId =  card.getCardId();
        Intent intent = new Intent(c, CurrentCarActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString("cardId",cardId);
        intent.putExtras(bundle);
        c.startActivity(intent);
    }

    @Override
    public void Success(String tag, OrderBean result) {
        if (tag.equals(MethodType.ORDER_DETAIL)) {
            if (result == null) {
                view.showError("未获取到订单数据");
                return;
            } else {
                card = result;
                view.refreshView(result);

            }
        }

        view.dismissLoad();
    }

    @Override
    public void Error(String tag, String error) {
        view.dismissLoad();
        view.showError(error);
    }

    @Override
    public void Exception(String tag, VolleyError error) {
        view.dismissLoad();
        view.showError(c.getString(R.string.system_error));
    }


}
